# -*- coding=utf-8 -*-
import requests
from lxml import etree


def getData(url):
    headers = {
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
    
    }
    resp = requests.get(url,headers=headers)
    text = resp.text
    
    tree = etree.HTML(text)
    print(tree)
     # 话题
    title = tree.xpath('//h1[@class="QuestionHeader-title"]')[0].text
    # 回答个数
    answerCount = tree.xpath('//meta[@itemprop="answerCount"]/@content')[0]
    # 关注人数
    numberBoard_itemValue1 = tree.xpath('//strong[@class="NumberBoard-itemValue"]/@title')[0]
    # 浏览量
    numberBoard_itemValue2 = tree.xpath('//strong[@class="NumberBoard-itemValue"]/@title')[1]
    return answerCount,numberBoard_itemValue1,numberBoard_itemValue2,title

#test    
if __name__ == '__main__':
     
    url = 'https://www.zhihu.com/question/313213582/answer/1635944568'
       
    data = getData(url)
    print(data)